package com.wechat.order.controller.excelController;

import com.wechat.order.util.ResultVOUtil;
import com.wechat.order.util.excelUtils.ExcelReport;
import com.wechat.order.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
/**
 * Created by zzy on 2017/12/31.
 */
@Slf4j
@Controller
@RequestMapping("/excel")
public class ExcelController {

    @GetMapping("/import")
    public ModelAndView index(HttpServletRequest request, Map map){
        map.put("request",request);
        return new ModelAndView("common/excelimport",map);
    }

    @RequestMapping("/download")
    public void download(HttpServletRequest request, HttpServletResponse response){
        String templateId=request.getParameter("templateId");
        ExcelReport excelReport=new ExcelReport(request,response);
        excelReport.exportTemplateToExcel();

    }

    @RequestMapping(value = "/import.json",method = RequestMethod.POST)
    @ResponseBody
    public ResultVO import2(@RequestParam("importFile") MultipartFile multipartFile) throws Exception {

        InputStream fs=multipartFile.getInputStream();
        List<List<String>> resultList=ExcelReport.readExcel(fs);
        log.info(resultList.toString());
        return ResultVOUtil.success();
    }

}
